package com.help.common.util;


import cn.hutool.core.codec.Base64;

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;


/**
 * 获取Signature签名
 * @author 风亦未止
 * @date 2021/10/5 17:59
 */
public class SignatureUtil {
    private static final String MAC_NAME = "HmacSHA1";
    public static final String ENCODING = "UTF-8";

    /**
     * 获取Signature签名
     * @param encryptText
     * @param encryptKey
     * @return
     * @throws Exception
     */
    public static String HmacSHA1Encrypt(String encryptText,String encryptKey ) throws Exception{
        byte[] data = encryptKey.getBytes( ENCODING );
        SecretKey secretKey = new SecretKeySpec( data, MAC_NAME );
        Mac mac = Mac.getInstance( MAC_NAME );
        mac.init( secretKey );
        byte[] text = encryptText.getBytes( ENCODING );
        byte[] digest = mac.doFinal( text );
        return new String(Base64.encode(digest));
    }



}
